package game.editer.ui;

import hx.events.Event;
import hx.events.MouseEvent;
import hx.layout.AnchorLayoutData;
import hx.layout.AnchorLayout;
import hx.display.Quad;
import hx.display.Box;

class CheckBox extends Box {
	private var __selectedQuad:Quad;

	public var selected(get, set):Bool;

	private function get_selected():Bool {
		return __selectedQuad.visible;
	}

	private function set_selected(value:Bool):Bool {
		__selectedQuad.visible = value;
		return value;
	}

	override function onInit() {
		super.onInit();

		this.width = 20;
		this.height = 20;

		this.layout = new AnchorLayout();
		var quad = new Quad(1, 1, 0x3e3e3e);
		this.addChild(quad);
		quad.layoutData = AnchorLayoutData.fill();

		__selectedQuad = new Quad(1, 1, 0xcacaca);
		this.addChild(__selectedQuad);
		__selectedQuad.layoutData = AnchorLayoutData.fill(4);

		this.addEventListener(MouseEvent.CLICK, onClick);
	}

	private function onClick(event:MouseEvent):Void {
		this.selected = !this.selected;
		this.dispatchEvent(new Event(Event.CHANGE));
	}
}
